package org.rcs.adslmonitor;

import java.awt.Point;
import java.awt.Window;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

class MoveWindowListener implements MouseMotionListener, MouseListener {

    private Point lastPoint;

    public MoveWindowListener(Window win) {
        win.addMouseListener(this);
        win.addMouseMotionListener(this);
    }

    public void mouseDragged(MouseEvent e) {
        Point newPos = e.getLocationOnScreen();
        Window win = (Window) e.getSource();
        Point winPos = win.getLocationOnScreen();
        win.setLocation(winPos.x + (newPos.x - lastPoint.x), winPos.y + (newPos.y - lastPoint.y));
        lastPoint = newPos;
    }

    public void mouseMoved(MouseEvent e) {
    }

    public void mouseClicked(MouseEvent e) {
    }

    public void mousePressed(MouseEvent e) {
        lastPoint = e.getLocationOnScreen();
    }

    public void mouseReleased(MouseEvent e) {
        lastPoint = null;
    }

    public void mouseEntered(MouseEvent e) {
    }

    public void mouseExited(MouseEvent e) {
    }
}
